package eleven.senven.hpb;

import android.app.Application;
import android.widget.Toast;

import com.lidroid.xutils.DbUtils;
import com.lidroid.xutils.bitmap.BitmapGlobalConfig;
import com.lidroid.xutils.cache.MD5FileNameGenerator;

import eleven.senven.hpb.config.AppConfig;
import eleven.senven.hpb.utils.FileUtils;


/**
 * Created by cnn on 2015/7/3.
 */
public class BaseApp extends Application {

    private static BaseApp application;

    private DbUtils dbUtils;

    @Override
    public void onCreate() {
        super.onCreate();
        application = this;
        configGlobalBitmap();

    }




    public static BaseApp getApplication() {
        return application;
    }



    private void configGlobalBitmap(){
        BitmapGlobalConfig config = BitmapGlobalConfig.getInstance(this, FileUtils.getImageCache());
        config.setDefaultCacheExpiry(1000L * 60 * 60 * 24 * 30);
        //过期时间
        config.setMemoryCacheSize(8 * 1024 * 1024);
        //内存
        config.setDiskCacheSize(1024 * 1024 * 100);
        //外存
        config.setThreadPoolSize(4);
        //线程数
        //保存图片的名字以md5命名
        config.setFileNameGenerator(new MD5FileNameGenerator());
    }

    public DbUtils getDbutils(){
        //
        if (dbUtils == null) {
            DbUtils.DaoConfig config = new DbUtils.DaoConfig(this);
            config.setDbDir(FileUtils.getDbPath());//路径
            config.setDbVersion(AppConfig.SQLDATAVERSION);//版本
            config.setDbName(AppConfig.SQLDATANAME);//数据库名称
            dbUtils = DbUtils.create(config);
        }
        return dbUtils;

    }

    public void show(String str){
        Toast.makeText(this,str,Toast.LENGTH_SHORT).show();
    }
}
